package com.zsjt.app.compoent.security.session;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Controller;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * 其他地方登录session失效处理策略
 */
@Slf4j
@Controller("sessionInformationExpiredStrategyImpl")
public class SessionInformationExpiredStrategyImpl implements SessionInformationExpiredStrategy {

    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent) throws IOException, ServletException {
        HttpServletResponse response = sessionInformationExpiredEvent.getResponse();
        HttpServletRequest request = sessionInformationExpiredEvent.getRequest();
//        request.setAttribute("LineOut",1);
//        request.getRequestDispatcher("/main").forward(request,response);
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().write("当前用户已在其他地方登录...");
    }
}
